<!-- xml version="1.0" encoding="utf-8" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<title>Latin Vocabulary</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<link href="classics.css" rel="stylesheet" type="text/css">
</head>
<?php

try {
	$db = new PDO('sqlite:LatinVocabulary.db3');
	$q = $db->query('SELECT DISTINCT liber FROM De_Bello_Gallico ORDER BY liber;');
	$libers = array();
	foreach( $q->fetchAll() as $row) {
		$libers[$row['liber']] = array();
	}
	
	foreach($libers as $liber => $alib) {
		$q = $db->query("SELECT DISTINCT caput FROM De_Bello_Gallico WHERE liber=$liber ORDER BY caput;");
		foreach( $q->fetchAll() as $row) {
			$libers[$liber][] = $row['caput'];
		}
	}

	$db = NULL;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>


<body>


<div id="container">
<div id="center">
<form name="v01" action="flashcard.php" method="post">
<table align="center">
<caption>De Bello Gallico</caption>
<?php
	foreach($libers as $liber => $alib) {
		print "<tr><th colspan=10 class=\"separate-above\">LIBER $liber</th></tr>\n";
		$n = 0;
		print "<tr>";
		foreach($alib as $caput) {
			print "<td><input type=\"checkbox\" name=\"capites[]\" value=\"$liber.$caput\" />$caput</td>";
			$n++;
			if (! ($n % 10)) {
				print "</tr>\n<tr>";
			}
		}
		print "</tr>\n";
	}
?>
<tr class="separate-above">
	<td align="center" colspan=10><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</div>

</body>
</html>
